package _02UDP通信;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.Arrays;

public class UDPReceiver {
    public static void main(String[] args) throws Exception {
        //1.创建接收端
        DatagramSocket socket = new DatagramSocket(9999);
        //2.创建用于接收的数组
        byte[] bytes = new byte[1024];
        //3.创建空的数据包用于接收发送端发送的数据
        DatagramPacket packet = new DatagramPacket(bytes,bytes.length);
        //4.接收数据
        socket.receive(packet);
        //5.打印数据
        System.out.println(new String(bytes,0,packet.getLength()));
        //6.关闭资源
        socket.close();
    }
}
